﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SharppiFlowEditor.models;
using System.Drawing;

namespace SharppiFlowEditor.views
{
    public class NodePropertiesView : ScrollableControl
    {

        private Label objTypeLabel, objTextLabel, nodeLocationXLabel, nodeLocationYLabel, connStartNodeLabel, connEndNodeLabel;
        private TextBox objTextTextBox, nodeLocationXTextBox, nodeLocationYTextBox;
        private ListBox objTypeListBox;
        private Font usedFont;
        private String[] nodeTypes;
        Button saveButton;

        public Button SaveButton { get { return saveButton; } }

        public String Title { get { return objTextTextBox.Text; } }

        public Point NodeLocation { get { return new Point(Convert.ToInt32(nodeLocationXTextBox.Text), Convert.ToInt32(nodeLocationYTextBox.Text)); } }

        public String NodeType { get { return Convert.ToString(objTypeListBox.SelectedItem); } }

        private Object _selectedGraphObject;
        public Object SelectedGraphObject
        {
            set { _selectedGraphObject = value; }
            get { return _selectedGraphObject; }
        }

        public NodePropertiesView()
        {
            usedFont = new Font(FontFamily.GenericSansSerif, 10.0F);

            this.Dock = DockStyle.Top;

            objTypeLabel = new Label();
            objTypeLabel.Text = "Type";
            objTypeLabel.Font = usedFont;
            objTypeLabel.Location = new Point(2, 110);
            objTypeLabel.Width = 55;
            objTextLabel = new Label();
            objTextLabel.Text = "Text";
            objTextLabel.Font = usedFont;
            objTextLabel.Location = new Point(2, 10);
            objTextLabel.Width = 55;
            nodeLocationXLabel = new Label();
            nodeLocationXLabel.Text = "x-point";
            nodeLocationXLabel.Font = usedFont;
            nodeLocationXLabel.Location = new Point(2, 40);
            nodeLocationXLabel.Width = 55;
            nodeLocationYLabel = new Label();
            nodeLocationYLabel.Text = "y-point";
            nodeLocationYLabel.Font = usedFont;
            nodeLocationYLabel.Location = new Point(2, 70);
            nodeLocationYLabel.Width = 55;

            objTextTextBox = new TextBox();
            objTextTextBox.Font = usedFont;
            objTextTextBox.Location = new Point(60, 10);
            objTextTextBox.Width = 100;
            nodeLocationXTextBox = new TextBox();
            nodeLocationXTextBox.Font = usedFont;
            nodeLocationXTextBox.Location = new Point(60, 40);
            nodeLocationXTextBox.Width = 100;
            nodeLocationYTextBox = new TextBox();
            nodeLocationYTextBox.Font = usedFont;
            nodeLocationYTextBox.Location = new Point(60, 70);
            nodeLocationYTextBox.Width = 100;
            objTypeListBox = new ListBox();
            objTypeListBox.Location = new Point(60, 110);
            objTypeListBox.Size = new Size(100, 60);
            objTypeListBox.SelectionMode = SelectionMode.One;


            //objTextTextBox.Enabled = false;
            //nodeLocationXTextBox.Enabled = false;
            //nodeLocationYTextBox.Enabled = false;
            //objTypeListBox.Enabled = false;

            saveButton = new Button();
            saveButton.Text = "Save";
            saveButton.Location = new Point(110, 170);
            saveButton.Size = new Size(50, 25);
            

            nodeTypes = new String[] { "Action Node", "Conditional Node", "End Node" };
            objTypeListBox.Items.AddRange(nodeTypes);
            this.Controls.Add(objTextLabel);
            this.Controls.Add(objTextTextBox);
            this.Controls.Add(nodeLocationXLabel);
            this.Controls.Add(nodeLocationXTextBox);
            this.Controls.Add(nodeLocationYLabel);
            this.Controls.Add(nodeLocationYTextBox);
            this.Controls.Add(objTypeLabel);
            this.Controls.Add(objTypeListBox);
            this.Controls.Add(saveButton);

            

        }


        // Set SelectedGraphObject-property before calling this.
        public void updatePropertiesView()
        {
            if (_selectedGraphObject is AbstractNode)
            {
                objTextTextBox.Text = ((AbstractNode)_selectedGraphObject).Title;
                nodeLocationXTextBox.Text = Convert.ToString(((AbstractNode)_selectedGraphObject).getBoundingRect().X);
                nodeLocationYTextBox.Text = Convert.ToString(((AbstractNode)_selectedGraphObject).getBoundingRect().Y);
                objTypeListBox.Items.Clear();
                objTypeListBox.Items.AddRange(nodeTypes);
                
            }
        }

        public void clearPropertiesView()
        {
            objTextTextBox.Text = "";
            nodeLocationXTextBox.Text = "";
            nodeLocationYTextBox.Text = "";
            objTypeListBox.Items.Clear();
        }

    }
}
